summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Simons <kevin.simons@nokia.com>2012-03-31 14:33:07 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-10 15:49:56 +0200
commit4921803cb9b3ed1341b5cc97ae7258182e5057e9 (patch)
treebd45f78c6ee2ae18583f54eb29b6ef80483f522e
parent03754f6a5f423c985c24c45a9c1e8144c1d53e29 (diff)
Switch to a partition-loading system based on files
The database searches through a set of paths looking for files named partitions*.json. These files contain a list of objects specifying the name and paths of partitions. The search path is defined as follows: 1) If a path is passed to jsondb, it is the first path searched, otherwise the current working directory is first 2) Next is the path specified by the environment variable JSONDB_CONFIG_SEARCH_PATH 3) Next is /etc/jsondb If no partitions*.json files are found, the database creates a single partition in the current working directory called "default". The partitions are reflected in the ephemeral partition as objects of type "Partition". A subsequent patch will make it an error to attempt to create an object of type "Partition". For now, these objects will just be ignored. The -base-name and -dbdir arguments to jsondb are now ignored. Change-Id: Idaed80444e17bd8b9c4f359c47233169263cedd9 Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
-rw-r--r--doc/src/partitions.qdoc57
-rw-r--r--src/clientcompat/jsondb-strings_p.h2
-rw-r--r--src/common/jsondb-strings.cpp2
-rw-r--r--src/daemon/dbserver.cpp220
-rw-r--r--src/daemon/dbserver.h6
-rw-r--r--src/daemon/jsondbsettings.cpp4
-rw-r--r--src/daemon/jsondbsettings.h6
-rw-r--r--src/daemon/main.cpp24
-rw-r--r--src/imports/jsondb/jsondatabase.cpp2
-rw-r--r--tests/auto/client/client.pro3
-rw-r--r--tests/auto/client/partitions.json5
-rw-r--r--tests/auto/client/test-jsondb-client.cpp25
-rw-r--r--tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp2
-rw-r--r--tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro3
-rw-r--r--tests/auto/jsondbcachinglistmodel/partitions.json4
-rw-r--r--tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp15
-rw-r--r--tests/auto/jsondblistmodel/jsondblistmodel.pro3
-rw-r--r--tests/auto/jsondblistmodel/partitions.json3
-rw-r--r--tests/auto/jsondblistmodel/testjsondblistmodel.cpp9
-rw-r--r--tests/auto/jsondbnotification/jsondbnotification.pro3
-rw-r--r--tests/auto/jsondbnotification/partitions.json3
-rw-r--r--tests/auto/jsondbnotification/testjsondbnotification.cpp11
-rw-r--r--tests/auto/jsondbpartition/jsondbpartition.pro3
-rw-r--r--tests/auto/jsondbpartition/partitions.json3
-rw-r--r--tests/auto/jsondbpartition/testjsondbpartition.cpp9
-rw-r--r--tests/auto/jsondbqueryobject/jsondbqueryobject.pro3
-rw-r--r--tests/auto/jsondbqueryobject/partitions.json3
-rw-r--r--tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp9
-rw-r--r--tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro3
-rw-r--r--tests/auto/jsondbsortinglistmodel/partitions.json4
-rw-r--r--tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp2
-rw-r--r--tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp2
-rw-r--r--tests/auto/qjsondbrequest/partitions.json3
-rw-r--r--tests/auto/qjsondbrequest/qjsondbrequest.pro3
-rw-r--r--tests/auto/qjsondbrequest/testqjsondbrequest.cpp110
-rw-r--r--tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp2
-rw-r--r--tests/benchmarks/client/client-benchmark.cpp2
-rw-r--r--tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp2
-rw-r--r--tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp2
-rw-r--r--tests/benchmarks/jsondbcachinglistmodel/partitions.json4
-rw-r--r--tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp2
-rw-r--r--tests/benchmarks/jsondbsortinglistmodel/partitions.json4
-rw-r--r--tests/shared/testhelper.cpp14
-rw-r--r--tests/shared/testhelper.h6
-rw-r--r--tests/shared/util.h8
45 files changed, 447 insertions, 168 deletions
diff --git a/doc/src/partitions.qdoc b/doc/src/partitions.qdoc
index 64911c2a..f1c52b50 100644
--- a/doc/src/partitions.qdoc
+++ b/doc/src/partitions.qdoc
@@ -41,6 +41,63 @@ The various partitions in a set are accessed via the \l {Partition} element in Q
C++, the partition is selected by \c setPartition() on a
\l {QJsonDbReadRequest}, \l {QJsonDbWriteRequest} or \l {QJsonDbWatcher}.
+\section1 Defining Partitions
+
+Partitions in JSON DB are defined via .json files. The filenames must be of the
+form \c partitions*.json. JSON DB searches a series of directories looking for
+such files and the search order is defined as follows:
+
+\list
+\li If a directory is passed as the final argument to the JSON DB binary (jsondb)
+then this location is searched first. If no argument is specified, the current
+working directory is searched.
+\li If the JSONDB_CONFIG_SEARCH_PATH environment variable points to a colon-separated
+list of directories, these are searched next.
+\li Finally, /etc/jsondb is searched.
+\endlist
+
+The partition definition files consist of an array of objects which define the
+partitions:
+\code
+[
+ {
+ "name" : "com.qt-project.partition1",
+ "default" : true
+ },
+ {
+ "name" : "com.qt-project.partition2",
+ "path" : "/var/run/jsondb/partition2"
+ }
+]
+\endcode
+
+The allowed properties:
+
+\table
+\row
+
+\row
+\li name
+\li The name of the partition, specified on all requests to the database.
+If more than one partition specifies the same \c name property, JSON DB
+only loads the first one it finds. See \l {Partition::name} and
+\l {QJsonDbRequest::partition}.
+
+\row
+\li path
+\li The path where the partition files should be stored. If not specified, it
+defaults to the current working directory.
+
+\row
+\li default
+\li If this boolean property is \c true, then requests which do not specify
+a partition will default this partition. If more than one partition is marked
+as default, JSON DB chooses one arbitrarily.
+\endtable
+
+If no partitions.json files are created, then the database defaults to a single
+partition with the name "default".
+
\section1 The Ephemeral Partition
JSON DB offers a partition called \c Ephemeral. Objects written to this
diff --git a/src/clientcompat/jsondb-strings_p.h b/src/clientcompat/jsondb-strings_p.h
index ee652e5e..88152d63 100644
--- a/src/clientcompat/jsondb-strings_p.h
+++ b/src/clientcompat/jsondb-strings_p.h
@@ -117,6 +117,8 @@ public:
static const QString kCaseSensitiveStr;
static const QString kCasePreferenceStr;
static const QString kDatabaseSchemaVersionStr;
+ static const QString kPathStr;
+ static const QString kDefaultStr;
};
QT_END_NAMESPACE_JSONDB
diff --git a/src/common/jsondb-strings.cpp b/src/common/jsondb-strings.cpp
index c7c028d0..c39821c8 100644
--- a/src/common/jsondb-strings.cpp
+++ b/src/common/jsondb-strings.cpp
@@ -112,5 +112,7 @@ const QString JsonDbString::kCollationStr = QString::fromLatin1("collation");
const QString JsonDbString::kCaseSensitiveStr = QString::fromLatin1("caseSensitive");
const QString JsonDbString::kCasePreferenceStr = QString::fromLatin1("casePreference");
const QString JsonDbString::kDatabaseSchemaVersionStr = QString::fromLatin1("databaseSchemaVersion");
+const QString JsonDbString::kPathStr = QString::fromLatin1("path");
+const QString JsonDbString::kDefaultStr = QString::fromLatin1("default");
QT_END_NAMESPACE_JSONDB
diff --git a/src/daemon/dbserver.cpp b/src/daemon/dbserver.cpp
index cb978618..725daaad 100644
--- a/src/daemon/dbserver.cpp
+++ b/src/daemon/dbserver.cpp
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#include <QtCore>
#include <QtNetwork>
+#include <QDir>
#include <QElapsedTimer>
#include "jsondb-strings.h"
@@ -90,38 +90,31 @@ static void sendError( JsonStream *stream, JsonDbError::ErrorCode code,
stream->send(map);
}
-DBServer::DBServer(const QString &filePath, const QString &baseName, QObject *parent)
- : QObject(parent),
- mDefaultPartition(0),
- mEphemeralPartition(0),
- mTcpServerPort(0),
- mServer(0),
- mTcpServer(0),
- mOwner(new JsonDbOwner(this)),
- mFilePath(filePath),
- mBaseName(baseName)
+DBServer::DBServer(const QString &searchPath, QObject *parent) :
+ QObject(parent)
+ , mDefaultPartition(0)
+ , mEphemeralPartition(0)
+ , mTcpServerPort(0)
+ , mServer(0)
+ , mTcpServer(0)
+ , mOwner(new JsonDbOwner(this))
{
// for queued connection handling
qRegisterMetaType<JsonDbPartition*>("JsonDbPartition*");
qRegisterMetaType<QSet<QString> >("QSet<QString>");
qRegisterMetaType<JsonDbUpdateList>("JsonDbUpdateList");
- QFileInfo info(filePath);
+ // make the user-specified path (or PWD) the first in the search path, then and
+ // the /etc one the last
+ QStringList searchPaths = jsondbSettings->configSearchPath();
+ if (searchPath.isEmpty())
+ searchPaths.prepend(QDir::currentPath());
+ else if (!searchPaths.contains(searchPath))
+ searchPaths.prepend(searchPath);
- if (QString::compare(info.suffix(), QLatin1String("db"), Qt::CaseInsensitive) == 0) {
- mFilePath = info.absolutePath();
- if (mBaseName.isEmpty())
- mBaseName = info.baseName();
- }
-
- if (mFilePath.isEmpty())
- mFilePath = QDir::currentPath();
- if (mBaseName.isEmpty())
- mBaseName = QLatin1String("default.System");
- if (!mBaseName.endsWith(QLatin1String(".System")))
- mBaseName += QLatin1String(".System");
-
- QDir(mFilePath).mkpath(QString("."));
+ if (!searchPaths.contains(QLatin1String("/etc/jsondb")))
+ searchPaths.append(QLatin1String("/etc/jsondb"));
+ jsondbSettings->setConfigSearchPath(searchPaths);
mOwner->setAllowAll(true);
}
@@ -148,6 +141,7 @@ void DBServer::sigHUP()
{
if (jsondbSettings->debug())
qDebug() << "SIGHUP received";
+ loadPartitions();
reduceMemoryUsage();
}
@@ -249,49 +243,87 @@ bool DBServer::loadPartitions()
this, SLOT(objectsUpdated(JsonDbUpdateList)));
}
- QHash<QString, JsonDbPartition*> oldPartitions = mPartitions;
- oldPartitions.remove(mBaseName);
+ QHash<QString, JsonDbPartition*> partitions;
+ QList<QJsonObject> definitions = findPartitionDefinitions();
+ QString defaultPartitionName;
- if (!mDefaultPartition) {
- mDefaultPartition = new JsonDbPartition(QDir(mFilePath).absoluteFilePath(mBaseName + QLatin1String(".db")),
- mBaseName, mOwner, this);
- connect(mDefaultPartition, SIGNAL(objectsUpdated(JsonDbUpdateList)),
- this, SLOT(objectsUpdated(JsonDbUpdateList)));
+ foreach (const QJsonObject &definition, definitions) {
+ QString name = definition.value(JsonDbString::kNameStr).toString();
- if (!mDefaultPartition->open())
- return false;
+ if (definition.value(JsonDbString::kDefaultStr).toBool() && defaultPartitionName.isEmpty())
+ defaultPartitionName = name;
- mPartitions[mBaseName] = mDefaultPartition;
- }
-
- QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(QLatin1String("[?_type=\"Partition\"]")));
- JsonDbQueryResult partitions = mDefaultPartition->queryObjects(mOwner, parsedQuery.data());
+ if (mPartitions.contains(name)) {
+ partitions[name] = mPartitions.take(name);
+ } else {
- foreach (const JsonDbObject &partition, partitions.data) {
- if (partition.contains(JsonDbString::kNameStr)) {
- QString name = partition.value(JsonDbString::kNameStr).toString();
+ if (partitions.contains(name)) {
+ qWarning() << "Duplicate partition name:" << name;
+ continue;
+ }
- if (!mPartitions.contains(name)) {
- QString filename = partition.contains(QLatin1String("file")) ?
- partition.value(QLatin1String("file")).toString() :
- QDir(mFilePath).absoluteFilePath(name + QLatin1String(".db"));
- JsonDbPartition *p = new JsonDbPartition(filename, name, mOwner, this);
- connect(p, SIGNAL(objectsUpdated(JsonDbUpdateList)),
- this, SLOT(objectsUpdated(JsonDbUpdateList)));
+ QString path = definition.value(JsonDbString::kPathStr).toString();
+ QDir pathDir(path);
+ pathDir.mkpath(QLatin1String("."));
- if (!p->open())
- return false;
+ JsonDbPartition *partition = new JsonDbPartition(pathDir.absoluteFilePath(name), name, mOwner, this);
+ partitions[name] = partition;
+ connect(partition, SIGNAL(objectsUpdated(JsonDbUpdateList)), this, SLOT(objectsUpdated(JsonDbUpdateList)));
- mPartitions[name] = p;
+ // TODO: for removable partitions, this shouldn't cause a total failure
+ if (!partition->open()) {
+ close();
+ return false;
}
- oldPartitions.remove(name);
+ // create an object in the Ephemeral partition to reflect this partition
+ JsonDbObject partitionRecord(definition);
+ partitionRecord.insert(JsonDbString::kUuidStr, JsonDbObject::createUuidFromString(name).toString());
+ partitionRecord.insert(JsonDbString::kTypeStr, JsonDbString::kPartitionTypeStr);
+ mEphemeralPartition->updateObjects(mOwner, JsonDbObjectList() << partitionRecord, JsonDbPartition::ForcedWrite);
}
}
// close any partitions that were declared previously but are no longer present
- foreach (JsonDbPartition *p, oldPartitions.values())
- p->close();
+ foreach (JsonDbPartition *partition, mPartitions.values()) {
+
+ if (mDefaultPartition == partition)
+ mDefaultPartition = 0;
+
+ QList<JsonDbObject> toRemove;
+
+ // remove the ephemeral object representing this partition
+ JsonDbObject partitionRecord;
+ partitionRecord.insert(JsonDbString::kUuidStr, JsonDbObject::createUuidFromString(partition->name()).toString());
+ partitionRecord.insert(JsonDbString::kTypeStr, JsonDbString::kPartitionTypeStr);
+ partitionRecord.markDeleted();
+ toRemove.append(partitionRecord);
+
+ // remove any notifications for the partition being closed
+ QJsonObject bindings;
+ bindings.insert(QLatin1String("notification"), JsonDbString::kNotificationTypeStr);
+ bindings.insert(QLatin1String("partition"), partition->name());
+
+ QScopedPointer<JsonDbQuery> query(JsonDbQuery::parse(QLatin1String("[?_type=%notification][?partition=%partition]"),
+ bindings));
+ JsonDbQueryResult results = mEphemeralPartition->queryObjects(mOwner, query.data());
+ foreach (const JsonDbObject &result, results.data) {
+ JsonDbObject notification = result;
+ notification.markDeleted();
+ toRemove.append(notification);
+ }
+
+ mEphemeralPartition->updateObjects(mOwner, toRemove, JsonDbPartition::ForcedWrite);
+
+ disconnect(partition, SIGNAL(objectsUpdated(JsonDbUpdateList)), this, SLOT(objectsUpdated(JsonDbUpdateList)));
+ partition->close();
+ delete partition;
+ }
+
+ mPartitions = partitions;
+
+ if (!mDefaultPartition)
+ mDefaultPartition = mPartitions[defaultPartitionName];
return true;
}
@@ -458,9 +490,12 @@ void DBServer::objectsUpdated(const QList<JsonDbUpdate> &objects)
else
return;
}
- quint32 partitionStateNumber = (partition
- ? partition->mainObjectTable()->stateNumber()
- : mDefaultPartition->mainObjectTable()->stateNumber());
+ quint32 partitionStateNumber = 0;
+ if (partition)
+ partition->mainObjectTable()->stateNumber();
+ else if (mDefaultPartition)
+ partitionStateNumber = mDefaultPartition->mainObjectTable()->stateNumber();
+
if (jsondbSettings->debug())
qDebug() << "objectsUpdated" << partitionName << partitionStateNumber;
@@ -481,7 +516,7 @@ void DBServer::objectsUpdated(const QList<JsonDbUpdate> &objects)
if (partition) {
JsonDbObjectTable *objectTable = partition->findObjectTable(objectType);
stateNumber = objectTable->stateNumber();
- } else
+ } else if (partitionName != mEphemeralPartition->name())
stateNumber = mDefaultPartition->mainObjectTable()->stateNumber();
QStringList notificationKeys;
@@ -737,10 +772,6 @@ void DBServer::processWrite(JsonStream *stream, JsonDbOwner *owner, const JsonDb
removeNotification(object);
if (!object.isDeleted())
createNotification(object, stream);
-
- // handle partitions
- } else if (object.type() == JsonDbString::kPartitionTypeStr) {
- loadPartitions();
}
}
@@ -1150,6 +1181,67 @@ JsonDbPartition *DBServer::findPartition(const QString &partitionName)
return partition;
}
+QList<QJsonObject> DBServer::findPartitionDefinitions() const
+{
+ QList<QJsonObject> partitions;
+
+ bool defaultSpecified = false;
+
+ foreach (const QString &path, jsondbSettings->configSearchPath()) {
+ QDir searchPath(path);
+ if (!searchPath.exists())
+ continue;
+
+ if (jsondbSettings->debug())
+ qDebug() << QString("Searching %1 for partition definition files").arg(path);
+
+ QStringList files = searchPath.entryList(QStringList() << "partitions*.json",
+ QDir::CaseSensitive | QDir::Files | QDir::Readable);
+ foreach (const QString file, files) {
+ if (jsondbSettings->debug())
+ qDebug() << QString("Loading partition definitions from %1").arg(file);
+
+ QFile partitionFile(searchPath.absoluteFilePath(file));
+ partitionFile.open(QFile::ReadOnly);
+
+ QJsonArray partitionList = QJsonDocument::fromJson(partitionFile.readAll()).array();
+ if (partitionList.isEmpty())
+ continue;
+
+ for (int i = 0; i < partitionList.count(); i++) {
+ QJsonObject def = partitionList[i].toObject();
+ if (def.contains(JsonDbString::kNameStr)) {
+ if (!def.contains(JsonDbString::kPathStr))
+ def.insert(JsonDbString::kPathStr, QDir::currentPath());
+ if (def.contains(JsonDbString::kDefaultStr))
+ defaultSpecified = true;
+ partitions.append(def);
+ }
+ }
+ }
+ }
+
+ // if no partitions are specified just make a partition in the current working
+ // directory and call it "default"
+ if (partitions.isEmpty()) {
+ QJsonObject defaultPartition;
+ defaultPartition.insert(JsonDbString::kNameStr, QLatin1String("default"));
+ defaultPartition.insert(JsonDbString::kPathStr, QDir::currentPath());
+ defaultPartition.insert(JsonDbString::kDefaultStr, true);
+ partitions.append(defaultPartition);
+ defaultSpecified = true;
+ }
+
+ // ensure that at least one partition is marked as default
+ if (!defaultSpecified) {
+ QJsonObject defaultPartition = partitions.takeFirst();
+ defaultPartition.insert(JsonDbString::kDefaultStr, true);
+ partitions.append(defaultPartition);
+ }
+
+ return partitions;
+}
+
void DBServer::receiveMessage(const QJsonObject &message)
{
JsonStream *stream = qobject_cast<JsonStream *>(sender());
diff --git a/src/daemon/dbserver.h b/src/daemon/dbserver.h
index 39d8c79f..34872482 100644
--- a/src/daemon/dbserver.h
+++ b/src/daemon/dbserver.h
@@ -68,8 +68,9 @@ class DBServer : public QObject
{
Q_OBJECT
public:
- DBServer(const QString &fileName, const QString &baseName, QObject *parent = 0);
+ DBServer(const QString &searchPath, QObject *parent = 0);
~DBServer();
+
void setTcpServerPort(quint16 port) { mTcpServerPort = port; }
quint16 tcpServerPort() const { return mTcpServerPort; }
@@ -121,6 +122,7 @@ private:
void updateEagerViewStateNumbers(JsonDbPartition *partition, quint32 partitionStateNumber);
JsonDbPartition* findPartition(const QString &partitionName);
+ QList<QJsonObject> findPartitionDefinitions() const;
JsonDbOwner *getOwner( JsonStream *stream);
JsonDbOwner *createDummyOwner( JsonStream *stream);
@@ -149,8 +151,6 @@ private:
JsonDbOwner *mOwner;
QMap<QIODevice*,JsonDbOwner*> mOwners;
QMap<QString,JsonStream *> mNotifications; // maps notification Id to socket
- QString mFilePath; // Directory where database files shall be stored
- QString mBaseName; // Prefix to use in database file names
bool mCompactOnClose;
};
diff --git a/src/daemon/jsondbsettings.cpp b/src/daemon/jsondbsettings.cpp
index cf349c59..50b936ba 100644
--- a/src/daemon/jsondbsettings.cpp
+++ b/src/daemon/jsondbsettings.cpp
@@ -90,7 +90,9 @@ void JsonDbSettings::loadEnvironment()
else if (property.type() == QVariant::Int)
property.write(this, qgetenv(envVariable.toLatin1()).toInt());
else if (property.type() == QVariant::String)
- property.write(this, envVariable);
+ property.write(this, qgetenv(envVariable.toLatin1()));
+ else if (property.type() == QVariant::StringList)
+ property.write(this, QString::fromLatin1(qgetenv(envVariable.toLatin1())).split(':'));
else
qWarning() << "JsonDbSettings: unknown property type" << property.name() << property.type();
}
diff --git a/src/daemon/jsondbsettings.h b/src/daemon/jsondbsettings.h
index c19af2d5..9980d4dc 100644
--- a/src/daemon/jsondbsettings.h
+++ b/src/daemon/jsondbsettings.h
@@ -45,6 +45,7 @@
#include "jsondb-global.h"
#include <QObject>
+#include <QStringList>
QT_BEGIN_HEADER
@@ -67,6 +68,7 @@ class JsonDbSettings : public QObject
Q_PROPERTY(int syncInterval READ syncInterval WRITE setSyncInterval)
Q_PROPERTY(int indexSyncInterval READ indexSyncInterval WRITE setIndexSyncInterval)
Q_PROPERTY(bool debugQuery READ debugQuery WRITE setDebugQuery)
+ Q_PROPERTY(QStringList configSearchPath READ configSearchPath WRITE setConfigSearchPath)
public:
static JsonDbSettings *instance();
@@ -109,6 +111,9 @@ public:
inline bool debugQuery() const { return mDebugQuery; }
inline void setDebugQuery(bool debug) { mDebugQuery = debug; }
+ inline QStringList configSearchPath() const { return mConfigSearchPath; }
+ inline void setConfigSearchPath(const QStringList &searchPath) { mConfigSearchPath = searchPath; }
+
JsonDbSettings();
private:
@@ -126,6 +131,7 @@ private:
int mSyncInterval;
int mIndexSyncInterval;
bool mDebugQuery;
+ QStringList mConfigSearchPath;
};
QT_END_NAMESPACE_JSONDB
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index a79a2289..35200cb0 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -113,8 +113,6 @@ static void usage()
{
cout << "Usage: " << qPrintable(progname) << " [OPTIONS] [FILENAME]" << endl
<< endl
- << " -dbdir Directory to use for database files. $HOME/.jsondb is the default." << endl
- << " -base-name Basename/prefix to be used in database files. Username of the process is the default." << endl
#ifdef Q_OS_LINUX
<< " -daemon Run as a daemon process" << endl
<< " -sigstop Send SIGSTOP to self when ready to notify upstart" << endl
@@ -164,10 +162,8 @@ int main(int argc, char * argv[])
QCoreApplication::setOrganizationDomain("nrcc.noklab.com");
QCoreApplication::setApplicationName("jsondb");
QCoreApplication::setApplicationVersion("1.0");
- QString arguments;
QString pidFileName;
- QString baseName;
- QString filePath;
+ QString searchPath;
quint16 port = 0;
bool clear = false;
rlim_t limit = 0;
@@ -227,9 +223,11 @@ int main(int argc, char * argv[])
} else if (arg == "-clear") {
clear = true;
} else if (arg == "-base-name") {
- baseName = args.takeFirst();
+ args.removeAt(0);
+ qWarning() << QLatin1String("The -base-name argument is no longer supported");
} else if (arg == "-dbdir") {
- filePath = args.takeFirst();
+ args.removeAt(0);
+ qWarning() << QLatin1String("The -dbdir argument is no longer supported");
} else if (arg == "-log-file") {
logFileName = args.takeFirst();
} else {
@@ -252,14 +250,8 @@ int main(int argc, char * argv[])
// FIXME: we should either support passing in the file or not
// missing dbdir and base-name with the file name is just bad
- if (args.size() == 1) {
- if (filePath.isEmpty()) {
- filePath = args.takeFirst();
- } else {
- qCritical() << "Cannot specify the file name in combination with -dbdir";
- usage();
- }
- }
+ if (args.size() == 1)
+ searchPath = args.takeFirst();
if (!args.isEmpty())
usage();
@@ -274,7 +266,7 @@ int main(int argc, char * argv[])
qInstallMsgHandler(logMessageOutput);
}
- DBServer server(filePath, baseName);
+ DBServer server(searchPath);
if (port)
server.setTcpServerPort(port);
JsonDbSignals handler;
diff --git a/src/imports/jsondb/jsondatabase.cpp b/src/imports/jsondb/jsondatabase.cpp
index ca990638..3d784287 100644
--- a/src/imports/jsondb/jsondatabase.cpp
+++ b/src/imports/jsondb/jsondatabase.cpp
@@ -119,8 +119,10 @@ void JsonDatabase::listPartitions(const QJSValue &listCallback)
qWarning() << "Invalid callback specified.";
return;
}
+
QJsonDbReadRequest *request = new QJsonDbReadRequest;
request->setQuery(QLatin1String("[?_type=\"Partition\"]"));
+ request->setPartition(QLatin1String("Ephemeral"));
connect(request, SIGNAL(finished()), this, SLOT(onQueryFinished()));
connect(request, SIGNAL(finished()), request, SLOT(deleteLater()));
connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
diff --git a/tests/auto/client/client.pro b/tests/auto/client/client.pro
index d2952953..765bdbc1 100644
--- a/tests/auto/client/client.pro
+++ b/tests/auto/client/client.pro
@@ -14,3 +14,6 @@ NSS_PREFIX = $$(NSS_PREFIX)
DEFINES += NSS_PREFIX=\\\"$$NSS_PREFIX\\\"
SOURCES += test-jsondb-client.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/client/partitions.json b/tests/auto/client/partitions.json
new file mode 100644
index 00000000..05222ec7
--- /dev/null
+++ b/tests/auto/client/partitions.json
@@ -0,0 +1,5 @@
+[
+ { "name" : "test-jsondb-client" },
+ { "name" : "com.example.autotest.Partition1" },
+ { "name" : "com.example.autotest.Partition2" }
+]
diff --git a/tests/auto/client/test-jsondb-client.cpp b/tests/auto/client/test-jsondb-client.cpp
index a343c216..c9262c97 100644
--- a/tests/auto/client/test-jsondb-client.cpp
+++ b/tests/auto/client/test-jsondb-client.cpp
@@ -248,7 +248,7 @@ void TestJsonDbClient::initTestCase()
arg_list << "-enforce-access-control";
arg_list << "-base-name";
arg_list << QString::fromLatin1(dbfileprefix);
- mProcess = launchJsonDbDaemonDetached(JSONDB_DAEMON_BASE, QString("testjsondb_%1").arg(getpid()), arg_list);
+ mProcess = launchJsonDbDaemonDetached(JSONDB_DAEMON_BASE, QString("testjsondb_%1").arg(getpid()), arg_list, __FILE__);
#endif
#if !defined(Q_OS_MAC)
if (wasRoot) {
@@ -256,7 +256,7 @@ void TestJsonDbClient::initTestCase()
JsonDbObject capa_obj;
capa_obj.insert(QLatin1String("_type"), QLatin1String("Capability"));
capa_obj.insert(QLatin1String("name"), QLatin1String("User"));
- capa_obj.insert(QLatin1String("partition"), QLatin1String(dbfileprefix) + QLatin1String(".System"));
+ capa_obj.insert(QLatin1String("partition"), QLatin1String("default"));
QVariantMap access_rules;
QVariantMap rw_rule;
rw_rule.insert(QLatin1String("read"), (QStringList() << QLatin1String("[*]")));
@@ -1572,24 +1572,7 @@ void TestJsonDbClient::partition()
const QString firstPartitionName = "com.example.autotest.Partition1";
const QString secondPartitionName = "com.example.autotest.Partition2";
- QVariantMap item;
- item.insert(JsonDbString::kTypeStr, "Partition");
- item.insert("name", firstPartitionName);
- id = mClient->create(item);
- waitForResponse1(id);
- QVERIFY(mData.toMap().contains("_uuid"));
- QVariant firstPartitionUuid = mData.toMap().value("_uuid");
-
- item = QVariantMap();
- item.insert(JsonDbString::kTypeStr, "Partition");
- item.insert("name", secondPartitionName);
- id = mClient->create(item);
- waitForResponse1(id);
- QVERIFY(mData.toMap().contains("_uuid"));
- QVariant secondPartitionUuid = mData.toMap().value("_uuid");
-
-
- item = QVariantMap();
+ QVariantMap item = QVariantMap();
item.insert(JsonDbString::kTypeStr, "Foobar");
item.insert("one", "one");
id = mClient->create(item, firstPartitionName);
@@ -1811,7 +1794,7 @@ void TestJsonDbClient::sigstop()
QStringList argList = QStringList() << "-sigstop";
argList << QString::fromLatin1("sigstop.db");
- QProcess *jsondb = launchJsonDbDaemon(JSONDB_DAEMON_BASE, QString("testjsondb_sigstop%1").arg(getpid()), argList);
+ QProcess *jsondb = launchJsonDbDaemon(JSONDB_DAEMON_BASE, QString("testjsondb_sigstop%1").arg(getpid()), argList, __FILE__);
int status;
::waitpid(jsondb->pid(), &status, WUNTRACED);
QVERIFY(WIFSTOPPED(status));
diff --git a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp
index 41ce2711..f0ba021a 100644
--- a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp
+++ b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp
@@ -104,7 +104,7 @@ void TestJsonDbListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
mClient = new JsonDbClient(this);
connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
diff --git a/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro b/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro
index 1762a90b..01e0ae4e 100644
--- a/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro
+++ b/tests/auto/jsondbcachinglistmodel/jsondbcachinglistmodel.pro
@@ -15,3 +15,6 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += testjsondbcachinglistmodel.h \
$$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbcachinglistmodel.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbcachinglistmodel/partitions.json b/tests/auto/jsondbcachinglistmodel/partitions.json
new file mode 100644
index 00000000..1cdd0fa5
--- /dev/null
+++ b/tests/auto/jsondbcachinglistmodel/partitions.json
@@ -0,0 +1,4 @@
+[
+ { "name" :"com.nokia.shared.1" },
+ { "name" :"com.nokia.shared.2" }
+]
diff --git a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp
index 136a4f33..e7f534cd 100644
--- a/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp
+++ b/tests/auto/jsondbcachinglistmodel/testjsondbcachinglistmodel.cpp
@@ -112,7 +112,7 @@ void TestJsonDbCachingListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
@@ -120,19 +120,6 @@ void TestJsonDbCachingListModel::initTestCase()
mPluginPath = findQMLPluginPath("QtJsonDb");
if (mPluginPath.isEmpty())
qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared.1");
- int id = create(item);
- waitForResponse1(id);
-
- item.clear();
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared.2");
- id = create(item);
- waitForResponse1(id);
}
QAbstractListModel *TestJsonDbCachingListModel::createModel()
diff --git a/tests/auto/jsondblistmodel/jsondblistmodel.pro b/tests/auto/jsondblistmodel/jsondblistmodel.pro
index b4f58d7d..1001c605 100644
--- a/tests/auto/jsondblistmodel/jsondblistmodel.pro
+++ b/tests/auto/jsondblistmodel/jsondblistmodel.pro
@@ -15,3 +15,6 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += testjsondblistmodel.h \
$$PWD/../../shared/requestwrapper.h
SOURCES += testjsondblistmodel.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondblistmodel/partitions.json b/tests/auto/jsondblistmodel/partitions.json
new file mode 100644
index 00000000..c312e702
--- /dev/null
+++ b/tests/auto/jsondblistmodel/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.example.shared.1" }
+]
diff --git a/tests/auto/jsondblistmodel/testjsondblistmodel.cpp b/tests/auto/jsondblistmodel/testjsondblistmodel.cpp
index 980b3105..bd0e40d7 100644
--- a/tests/auto/jsondblistmodel/testjsondblistmodel.cpp
+++ b/tests/auto/jsondblistmodel/testjsondblistmodel.cpp
@@ -130,7 +130,7 @@ void TestJsonDbListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
@@ -138,13 +138,6 @@ void TestJsonDbListModel::initTestCase()
mPluginPath = findQMLPluginPath("QtJsonDb");
if (mPluginPath.isEmpty())
qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.example.shared.1");
- int id = create(item);
- waitForResponse1(id);
}
QAbstractItemModel *TestJsonDbListModel::createModel()
diff --git a/tests/auto/jsondbnotification/jsondbnotification.pro b/tests/auto/jsondbnotification/jsondbnotification.pro
index b02e97a1..1703343d 100644
--- a/tests/auto/jsondbnotification/jsondbnotification.pro
+++ b/tests/auto/jsondbnotification/jsondbnotification.pro
@@ -15,3 +15,6 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += testjsondbnotification.h \
$$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbnotification.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbnotification/partitions.json b/tests/auto/jsondbnotification/partitions.json
new file mode 100644
index 00000000..c77651a0
--- /dev/null
+++ b/tests/auto/jsondbnotification/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared" }
+]
diff --git a/tests/auto/jsondbnotification/testjsondbnotification.cpp b/tests/auto/jsondbnotification/testjsondbnotification.cpp
index 2b127324..418b1100 100644
--- a/tests/auto/jsondbnotification/testjsondbnotification.cpp
+++ b/tests/auto/jsondbnotification/testjsondbnotification.cpp
@@ -122,21 +122,12 @@ void TestJsonDbNotification::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
- if (mPluginPath.isEmpty())
- qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared");
- int id = create(item);
- waitForResponse1(id);
}
ComponentData *TestJsonDbNotification::createComponent()
diff --git a/tests/auto/jsondbpartition/jsondbpartition.pro b/tests/auto/jsondbpartition/jsondbpartition.pro
index b588b0f2..be202eb4 100644
--- a/tests/auto/jsondbpartition/jsondbpartition.pro
+++ b/tests/auto/jsondbpartition/jsondbpartition.pro
@@ -15,3 +15,6 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += testjsondbpartition.h \
$$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbpartition.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbpartition/partitions.json b/tests/auto/jsondbpartition/partitions.json
new file mode 100644
index 00000000..9788d134
--- /dev/null
+++ b/tests/auto/jsondbpartition/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared.1" }
+]
diff --git a/tests/auto/jsondbpartition/testjsondbpartition.cpp b/tests/auto/jsondbpartition/testjsondbpartition.cpp
index 018c698a..2f275434 100644
--- a/tests/auto/jsondbpartition/testjsondbpartition.cpp
+++ b/tests/auto/jsondbpartition/testjsondbpartition.cpp
@@ -93,7 +93,7 @@ void TestJsonDbPartition::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
@@ -101,13 +101,6 @@ void TestJsonDbPartition::initTestCase()
mPluginPath = findQMLPluginPath("QtJsonDb");
if (mPluginPath.isEmpty())
qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared.1");
- int id = RequestWrapper::create(item);
- waitForResponse1(id);
}
ComponentData *TestJsonDbPartition::createComponent()
diff --git a/tests/auto/jsondbqueryobject/jsondbqueryobject.pro b/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
index 3b19ea1e..717acef4 100644
--- a/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
+++ b/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
@@ -15,3 +15,6 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += testjsondbqueryobject.h \
$$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbqueryobject.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbqueryobject/partitions.json b/tests/auto/jsondbqueryobject/partitions.json
new file mode 100644
index 00000000..c77651a0
--- /dev/null
+++ b/tests/auto/jsondbqueryobject/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared" }
+]
diff --git a/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp b/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
index 59a49aea..2a214dbb 100644
--- a/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
+++ b/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
@@ -110,7 +110,7 @@ void TestJsonDbQueryObject::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
@@ -118,13 +118,6 @@ void TestJsonDbQueryObject::initTestCase()
mPluginPath = findQMLPluginPath("QtJsonDb");
if (mPluginPath.isEmpty())
qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared");
- int id = create(item);
- waitForResponse1(id);
}
ComponentData *TestJsonDbQueryObject::createComponent(const QString &qml)
diff --git a/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro b/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro
index ec3fb699..7d1b4f74 100644
--- a/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro
+++ b/tests/auto/jsondbsortinglistmodel/jsondbsortinglistmodel.pro
@@ -15,3 +15,6 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += testjsondbsortinglistmodel.h \
$$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbsortinglistmodel.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbsortinglistmodel/partitions.json b/tests/auto/jsondbsortinglistmodel/partitions.json
new file mode 100644
index 00000000..1cdd0fa5
--- /dev/null
+++ b/tests/auto/jsondbsortinglistmodel/partitions.json
@@ -0,0 +1,4 @@
+[
+ { "name" :"com.nokia.shared.1" },
+ { "name" :"com.nokia.shared.2" }
+]
diff --git a/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp b/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp
index 5f828833..f9edeedb 100644
--- a/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp
+++ b/tests/auto/jsondbsortinglistmodel/testjsondbsortinglistmodel.cpp
@@ -136,7 +136,7 @@ void TestJsonDbSortingListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
diff --git a/tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp b/tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp
index a000a07b..929e0420 100644
--- a/tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp
+++ b/tests/auto/qjsondbflushrequest/testqjsondbflushrequest.cpp
@@ -64,7 +64,7 @@ void TestQJsonDbFlushRequest::initTestCase()
removeDbFiles();
QStringList arg_list = QStringList() << "-validate-schemas";
- launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list);
+ launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list, __FILE__);
}
void TestQJsonDbFlushRequest::cleanupTestCase()
diff --git a/tests/auto/qjsondbrequest/partitions.json b/tests/auto/qjsondbrequest/partitions.json
new file mode 100644
index 00000000..56139e6a
--- /dev/null
+++ b/tests/auto/qjsondbrequest/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.qt-project.shared", "default" : true }
+]
diff --git a/tests/auto/qjsondbrequest/qjsondbrequest.pro b/tests/auto/qjsondbrequest/qjsondbrequest.pro
index b34a6f85..ab4b22ca 100644
--- a/tests/auto/qjsondbrequest/qjsondbrequest.pro
+++ b/tests/auto/qjsondbrequest/qjsondbrequest.pro
@@ -12,3 +12,6 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
RESOURCES += ../daemon/daemon.qrc
SOURCES += testqjsondbrequest.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/qjsondbrequest/testqjsondbrequest.cpp b/tests/auto/qjsondbrequest/testqjsondbrequest.cpp
index 9d66b9fb..a6df7f95 100644
--- a/tests/auto/qjsondbrequest/testqjsondbrequest.cpp
+++ b/tests/auto/qjsondbrequest/testqjsondbrequest.cpp
@@ -40,10 +40,19 @@
****************************************************************************/
#include "qjsondbconnection.h"
+#include "qjsondbobject.h"
+#include "qjsondbreadrequest.h"
+#include "qjsondbwriterequest.h"
#include "testhelper.h"
+#include <QDebug>
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QProcess>
#include <QTest>
+#include <signal.h>
+
QT_USE_NAMESPACE_JSONDB
static const char dbfileprefix[] = "test-jsondb-request";
@@ -57,6 +66,8 @@ private slots:
void cleanupTestCase();
void init();
void cleanup();
+
+ void modifyPartitions();
};
void TestQJsonDbRequest::initTestCase()
@@ -64,7 +75,7 @@ void TestQJsonDbRequest::initTestCase()
removeDbFiles();
QStringList arg_list = QStringList() << "-validate-schemas";
- launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list);
+ launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list, __FILE__);
}
void TestQJsonDbRequest::cleanupTestCase()
@@ -83,6 +94,103 @@ void TestQJsonDbRequest::cleanup()
disconnectFromServer();
}
+void TestQJsonDbRequest::modifyPartitions()
+{
+ // create a notification on Partitions
+ QJsonDbWatcher watcher;
+ watcher.setPartition(QLatin1String("Ephemeral"));
+ watcher.setQuery("[?_type=\"Partition\"]");
+ mConnection->addWatcher(&watcher);
+
+ // ensure that there's only one partition defined and that it's the default
+ QLatin1String defaultPartition("com.qt-project.shared");
+
+ QJsonDbReadRequest partitionQuery;
+ partitionQuery.setPartition(QLatin1String("Ephemeral"));
+ partitionQuery.setQuery(QLatin1String("[?_type=%type]"));
+ partitionQuery.bindValue(QLatin1String("type"), QLatin1String("Partition"));
+
+ mConnection->send(&partitionQuery);
+ waitForResponse(&partitionQuery);
+
+ QList<QJsonObject> results = partitionQuery.takeResults();
+ QCOMPARE(results.count(), 1);
+ QCOMPARE(results[0].value(QLatin1String("name")).toString(), defaultPartition);
+ QVERIFY(results[0].value(QLatin1String("default")).toBool());
+
+ // write a new partitions file
+ QJsonObject def1;
+ def1.insert(QLatin1String("name"), QLatin1String("com.qt-project.test1"));
+ QJsonObject def2;
+ def2.insert(QLatin1String("name"), QLatin1String("com.qt-project.test2"));
+ QJsonArray defs;
+ defs.append(def1);
+ defs.append(def2);
+
+ QFile partitionsFile(QLatin1String("partitions-test.json"));
+ partitionsFile.open(QFile::WriteOnly);
+ partitionsFile.write(QJsonDocument(defs).toJson());
+ partitionsFile.close();
+
+ // send the daemon a SIGHUP to get it to reload the partitions
+ kill(mProcess->pid(), SIGHUP);
+ waitForResponseAndNotifications(0, &watcher, 2);
+
+ // query for the new partitions
+ mConnection->send(&partitionQuery);
+ waitForResponse(&partitionQuery);
+
+ results = partitionQuery.takeResults();
+ QCOMPARE(results.count(), 3);
+
+ // operate on the new partition to make sure it works
+ QJsonDbWriteRequest writeRequest;
+ QUuid testUuid = QJsonDbObject::createUuidFromString(QLatin1String("testobject1"));
+ QJsonDbObject toWrite;
+ toWrite.setUuid(testUuid);
+ toWrite.insert(QLatin1String("_type"), QLatin1String("TestObject"));
+ writeRequest.setObjects(QList<QJsonObject>() << toWrite);
+ mConnection->send(&writeRequest);
+ waitForResponse(&writeRequest);
+ QVERIFY(!mRequestErrors.contains(&writeRequest));
+
+ QJsonDbReadObjectRequest readRequest(testUuid);
+ mConnection->send(&readRequest);
+ waitForResponse(&readRequest);
+ QVERIFY(!mRequestErrors.contains(&readRequest));
+ results = readRequest.takeResults();
+ QCOMPARE(results.count(), 1);
+ QCOMPARE(results[0].value(QLatin1String("_type")).toString(), QLatin1String("TestObject"));
+
+ // remove the new partitions file
+ partitionsFile.remove();
+
+ // send the daemon a SIGHUP to get it to unload the partitions
+ kill(mProcess->pid(), SIGHUP);
+ waitForResponseAndNotifications(0, &watcher, 2);
+
+ // verify that we're back to just the origin partition
+ mConnection->send(&partitionQuery);
+ waitForResponse(&partitionQuery);
+
+ results = partitionQuery.takeResults();
+ QCOMPARE(results.count(), 1);
+ QCOMPARE(results[0].value(QLatin1String("name")).toString(), defaultPartition);
+ QVERIFY(results[0].value(QLatin1String("default")).toBool());
+
+ // query one of the test partitions to ensure we get an InvalidPartition error
+ QJsonDbReadRequest failingRequest;
+ failingRequest.setPartition(QLatin1String("com.qt-project.test1"));
+ failingRequest.setQuery(QLatin1String("[*]"));
+ mConnection->send(&failingRequest);
+ waitForResponse(&failingRequest);
+
+ QVERIFY(mRequestErrors.contains(&failingRequest));
+ QCOMPARE(mRequestErrors[&failingRequest], QJsonDbRequest::InvalidPartition);
+
+ mConnection->removeWatcher(&watcher);
+}
+
QTEST_MAIN(TestQJsonDbRequest)
#include "testqjsondbrequest.moc"
diff --git a/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp b/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp
index e4cba386..e3b337a1 100644
--- a/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp
+++ b/tests/auto/qjsondbwatcher/testqjsondbwatcher.cpp
@@ -107,7 +107,7 @@ void TestQJsonDbWatcher::initTestCase()
removeDbFiles();
QStringList arg_list = QStringList() << "-validate-schemas";
- launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list);
+ launchJsonDbDaemon(QString::fromLatin1(dbfileprefix), arg_list, __FILE__);
}
void TestQJsonDbWatcher::cleanupTestCase()
diff --git a/tests/benchmarks/client/client-benchmark.cpp b/tests/benchmarks/client/client-benchmark.cpp
index 51dd827a..fc8e0b75 100644
--- a/tests/benchmarks/client/client-benchmark.cpp
+++ b/tests/benchmarks/client/client-benchmark.cpp
@@ -92,7 +92,7 @@ void TestJson::initTestCase()
#ifndef DONT_START_SERVER
removeDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
#endif
connectToServer();
diff --git a/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp b/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp
index a0eb763a..bfbf7d76 100644
--- a/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp
+++ b/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp
@@ -102,7 +102,7 @@ void TestListModel::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
mClient = new JsonDbClient(this);
QVERIFY(mClient!= 0);
diff --git a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp
index dd682e9a..9a3e430a 100644
--- a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp
+++ b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp
@@ -115,7 +115,7 @@ void JsonDbCachingListModelBench::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
diff --git a/tests/benchmarks/jsondbcachinglistmodel/partitions.json b/tests/benchmarks/jsondbcachinglistmodel/partitions.json
new file mode 100644
index 00000000..1cdd0fa5
--- /dev/null
+++ b/tests/benchmarks/jsondbcachinglistmodel/partitions.json
@@ -0,0 +1,4 @@
+[
+ { "name" :"com.nokia.shared.1" },
+ { "name" :"com.nokia.shared.2" }
+]
diff --git a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp
index a814232e..1e993060 100644
--- a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp
+++ b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp
@@ -110,7 +110,7 @@ void JsonDbSortingListModelBench::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
connection = new QJsonDbConnection();
connection->connectToServer();
diff --git a/tests/benchmarks/jsondbsortinglistmodel/partitions.json b/tests/benchmarks/jsondbsortinglistmodel/partitions.json
new file mode 100644
index 00000000..1cdd0fa5
--- /dev/null
+++ b/tests/benchmarks/jsondbsortinglistmodel/partitions.json
@@ -0,0 +1,4 @@
+[
+ { "name" :"com.nokia.shared.1" },
+ { "name" :"com.nokia.shared.2" }
+]
diff --git a/tests/shared/testhelper.cpp b/tests/shared/testhelper.cpp
index e630ffa0..961a533e 100644
--- a/tests/shared/testhelper.cpp
+++ b/tests/shared/testhelper.cpp
@@ -82,8 +82,10 @@ QJsonDocument TestHelper::readJsonFile(const QString &filename, QJsonParseError
return doc;
}
-void TestHelper::launchJsonDbDaemon(const QString &basename, const QStringList &args)
+void TestHelper::launchJsonDbDaemon(const QString &basename, const QStringList &args, const char *sourceFile)
{
+ qputenv("JSONDB_CONFIG_SEARCH_PATH", QFileInfo(QString::fromUtf8(sourceFile)).dir().absolutePath().toUtf8());
+
if (dontLaunch())
return;
@@ -136,8 +138,10 @@ void TestHelper::launchJsonDbDaemon(const QString &basename, const QStringList &
qFatal("Unable to connect to jsondb process");
}
-inline qint64 TestHelper::launchJsonDbDaemonDetached(const QString &basename, const QStringList &args)
+inline qint64 TestHelper::launchJsonDbDaemonDetached(const QString &basename, const QStringList &args, const char *sourceFile)
{
+ qputenv("JSONDB_CONFIG_SEARCH_PATH", QFileInfo(QString::fromUtf8(sourceFile)).dir().absolutePath().toUtf8());
+
if (dontLaunch())
return 0;
@@ -210,6 +214,8 @@ void TestHelper::disconnectFromServer()
delete mConnection;
mConnection = 0;
}
+
+ mRequestErrors.clear();
}
void TestHelper::removeDbFiles(const QStringList &additionalFiles)
@@ -364,6 +370,10 @@ void TestHelper::requestFinished()
void TestHelper::requestError(QtJsonDb::QJsonDbRequest::ErrorCode code, QString msg)
{
qWarning() << "Request error:" << code << msg;
+ QJsonDbRequest *request = qobject_cast<QJsonDbRequest*>(sender());
+ if (request)
+ mRequestErrors[request] = code;
+
requestFinished();
}
diff --git a/tests/shared/testhelper.h b/tests/shared/testhelper.h
index 5d082b5e..1a148254 100644
--- a/tests/shared/testhelper.h
+++ b/tests/shared/testhelper.h
@@ -47,6 +47,7 @@
#include <QJsonDbWatcher>
#include <QEventLoop>
+#include <QHash>
#include <QJsonDocument>
#include <QJsonValue>
#include <QObject>
@@ -67,8 +68,8 @@ public:
QJsonDocument readJsonFile(const QString &filename, QJsonParseError *error = 0);
- void launchJsonDbDaemon(const QString &basename, const QStringList &args);
- qint64 launchJsonDbDaemonDetached(const QString &basename, const QStringList &args);
+ void launchJsonDbDaemon(const QString &basename, const QStringList &args, const char *sourceFile);
+ qint64 launchJsonDbDaemonDetached(const QString &basename, const QStringList &args, const char *sourceFile);
void stopDaemon();
void connectToServer();
@@ -93,6 +94,7 @@ protected:
int mNotificationsExpected;
int mLastStateChangedExpected;
int mLastStateChangedReceived;
+ QHash<QtJsonDb::QJsonDbRequest *, QtJsonDb::QJsonDbRequest::ErrorCode> mRequestErrors;
protected Q_SLOTS:
void connectionError(QtJsonDb::QJsonDbConnection::ErrorCode code, QString msg);
diff --git a/tests/shared/util.h b/tests/shared/util.h
index 0671f2f7..93b43537 100644
--- a/tests/shared/util.h
+++ b/tests/shared/util.h
@@ -92,8 +92,10 @@ inline QJsonValue readJsonFile(const QString &filename, QJsonParseError *error =
return doc.isArray() ? QJsonValue(doc.array()) : QJsonValue(doc.object());
}
-inline QProcess *launchJsonDbDaemon(const char *prefix, const QString &socketName, const QStringList &args)
+inline QProcess *launchJsonDbDaemon(const char *prefix, const QString &socketName, const QStringList &args, const char *sourceFile)
{
+ qputenv("JSONDB_CONFIG_SEARCH_PATH", QFileInfo(QString::fromUtf8(sourceFile)).dir().absolutePath().toUtf8());
+
static bool dontlaunch = qgetenv("AUTOTEST_DONT_LAUNCH_JSONDB").toInt() == 1;
static bool useValgrind = qgetenv("AUTOTEST_VALGRIND_JSONDB").toInt() == 1;
if (dontlaunch)
@@ -135,8 +137,10 @@ inline QProcess *launchJsonDbDaemon(const char *prefix, const QString &socketNam
return process;
}
-inline qint64 launchJsonDbDaemonDetached(const char *prefix, const QString &socketName, const QStringList &args)
+inline qint64 launchJsonDbDaemonDetached(const char *prefix, const QString &socketName, const QStringList &args, const char *sourceFile)
{
+ qputenv("JSONDB_CONFIG_SEARCH_PATH", QFileInfo(QString::fromUtf8(sourceFile)).dir().absolutePath().toUtf8());
+
static bool dontlaunch = qgetenv("AUTOTEST_DONT_LAUNCH_JSONDB").toInt() == 1;
static bool useValgrind = qgetenv("AUTOTEST_VALGRIND_JSONDB").toInt() == 1;
if (dontlaunch)